<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <style>
        .hide{
            pointer-events: none;
            color: gray;
        }
    </style>
    <script src="js/jquery-3.6.3.min.js.txt"></script>
    <script>
        $(function () {
            $("#go").click(function () {
                let pageNo=$(this).prev().val();
                window.location="subject.do?pageNo="+pageNo+"&subjectname=${sname}";
            });
        });
    </script>
</head>
<body>
<%@include file="/checkLogin.jsp"%>
<div>

    <form action="subject.do">
        <input name="subjectname" value="${sname}" placeholder="课程名"/>
        <input type="submit" value="搜索"/>
    </form>
    <a href="toAddSubject.do"> <input type="button" value="添加新课程"></a>
</div>

<table border="1" width="85%">
    <tr bgcolor="#d3d3d3">
        <th>编号</th>
        <th>课程名</th>
        <th>课时</th>
        <th>年级</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${p.data}" var="s">
    <tr>
        <td>${s.id}</td>
        <td>${s.subjectname}
        </td>
        <td>${s.classhour}
        </td>
        <td>${s.gname}
        </td>
        <td><a href="updateSubject.jsp?id=${s.id}">编辑</a>
            &nbsp;&nbsp;
        <a onclick="return confirm('真的要删除这门课?')" href="delsubject.do?id=${s.id}">删除</a></td>
    </tr>
    </c:forEach>

</table>
<p>
    <a href="subject.do?pageNo=1&subjectname=${sname}">首页</a>
    <a  <c:if test="${p.pageNo<=1}">class='hide'</c:if>  href="subject.do?pageNo=${p.pageNo-1}&subjectname=${sname}">上一页</a>

    <input type="number" min="1" id="goto" value="${p.pageNo}" max="${p.pageTotal}" style="width: 48px" />/${p.pageTotal}<input type="button" id="go" value="Go"/>

    <a   <c:if test="${p.pageNo>=p.pageTotal}">class='hide'</c:if> href="subject.do?pageNo=${p.pageNo+1}&subjectname=${sname}">下一页</a>
    <a href="subject.do?pageNo=${p.getPageTotal()}&subjectname=${sname}">尾页</a>
</p>
</body>
</html>
